package oop.inherit.account;

public class CheckAccount extends Account{

    private double overdraft;

    public double getOverdraft() {
        return overdraft;
    }

    public void setOverdraft(double overdraft) {
        this.overdraft = overdraft;
    }

    @Override
    public void withdraw(double amount) {
        double balance = this.getBalance();
        if(amount <= balance){
            this.setBalance(balance - amount);
        }else{
            if((this.overdraft + balance)<amount){
                System.out.println("用户超过可透支额的限额");
            }else{
                this.setBalance(0);
                this.overdraft -= amount-balance;
            }
        }
    }

    public CheckAccount(
            int id,
            double balance,
            double annualInterestRate,
            double overdraft) {
        super(id, balance, annualInterestRate);
        this.overdraft = overdraft;
    }
}
